/*
 * NonMotorizedSubtrip.java
 *
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.core.trip;

import org.fpdev.core.basenet.BLink;
import org.fpdev.core.basenet.Path;
import org.fpdev.core.basenet.BaseNetwork;
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.fpdev.core.basenet.*;
import org.fpdev.apps.rtemaster.gui.map.MapCanvas;
import org.fpdev.util.FPUtil;

public abstract class NonMotorizedSubtrip implements TripItem {

  protected int start_,  end_;
  protected Path path_;

  public NonMotorizedSubtrip(Path path, int start, int end) {
    path_ = path;
    start_ = start;
    end_ = end;
  }

  public abstract String getItemName();

  public String getName() {
    return path_.startLink().getDisplayName();
  }

  public String getFrom(BaseNetwork net) {
    return path_.startNode().getDisplayName(net);
  }

  public String getTo(BaseNetwork net) {
    return path_.endNode().getDisplayName(net);
  }

  public Path getPath() {
    return path_;
  }

  public int getStart() {
    return start_;
  }

  public int getEnd() {
    return end_;
  }

  public List<Integer> getLinkIDList() {
    List<Integer> list = new LinkedList<Integer>();
    Iterator<BLink> pLinks = path_.getLinks();
    while (pLinks.hasNext()) {
      list.add(pLinks.next().getID());
    }
    return list;
  }

  public String getXml(BaseNetwork net) {
    String links = "";
    Iterator<BLink> pLinks = path_.getLinks();
    while (pLinks.hasNext()) {
      links += pLinks.next().getID() + ",";
    }
    return "      <" + getItemName() + " name=\"" + getName() + "\" dir=\"" + getDirection() + "\" from=\"" + getFrom(net) + "\" to=\"" + getTo(net) + "\" stime=\"" + getStart() + "\" etime=\"" + getEnd() + "\" len=\"" + path_.lengthFt(false) + "\"" + getMoreXML() + ">" + links + "</" + getItemName() + ">\n";
  }

  protected String getMoreXML() {
    return "";
  }

  public String getText() {
    return "";
  }

  public String getDirection() {
    return FPUtil.directionStr(path_.endNode().getX() - path_.startNode().getX(), path_.endNode().getY() - path_.startNode().getY());
  }

  public int subItemCount() {
    return 1;
  }

  public void draw(MapCanvas canvas) {
    path_.draw(canvas, Color.green, 3, true);
  }

  public Rectangle2D.Double getBoundingBox() {
    return path_.getBoundingBox();
  }

  public int getMinElev() {
    int min = Integer.MAX_VALUE;
    for (BLink link : path_.getLinkSet()) {
      int lm = link.getMinElev();
      min = Math.min(min, lm);
    }
    return min;
    
  }

  public int getMaxElev() {
    int max = Integer.MIN_VALUE;
    Iterator<BLink> pLinks = path_.getLinks();
    while (pLinks.hasNext()) {
      max = Math.max(max, pLinks.next().getMaxElev());
    }
    return max;
  }
}
























